package com.ld.admin.util.daliySentence.impl;

import com.alibaba.fastjson.JSONObject;
import com.ld.admin.util.daliySentence.DaliySentence;
import com.ld.admin.util.daliySentence.DaliySentenceUtil;
import com.ld.admin.util.daliySentence.model.DaliySentenceModel;
import com.ld.shieldsb.common.core.util.JsoupUtil;

/**
 * 
 * 金山词霸/爱词霸每日一句
 * 
 * @author <a href="mailto:donggongai@126.com" target="_blank">吕凯</a>
 * @date 2020年1月8日 上午11:00:51
 *
 */
public class DaliySentenceIciba implements DaliySentence {
    public static final String KEY = "iciba";
    public static final String NAME = "爱词霸";
    // 同类型的还有http://dict.cn/
    public static final String URL_ICIBA = "http://open.iciba.com/dsapi"; // 金山词霸
    public static final String LINK_URL = "http://open.iciba.com/dsapi";
    public static final String DESCRIPTION = ""; // 描述

    @Override
    public DaliySentenceModel getSentence() {
        DaliySentenceModel model = null;
        String htmlContent = null;
        JSONObject jsonObj = JsoupUtil.getRemoteURLJson(getURL());
        /*       
         * "sid":"3622",
         * "tts":"https://edu-wps.ks3-cn-beijing.ksyun.com/audio/b3ecbafc8a4bfad2fcde184d75b81d74.mp3",
         * "content":"Find a truly original idea. It is the only way I will ever distinguish myself. It is the only way I will ever matter.",
         * "note":"找到真正的原创思想。这是唯一能够使我永远与众不同的方法，是唯一能让我举足轻重的方法。",
         * "love":"198","translation":"新版每日一句",
         * "picture":"https://edu-wps.ks3-cn-beijing.ksyun.com/image/213b880e693178c1a9bb01c5e60ad208.jpg",
         * "picture2":"https://edu-wps.ks3-cn-beijing.ksyun.com/image/31918a2a573cb047957ce94efd74edae.jpg",
         * "caption":"词霸每日一句",
         * "dateline":"2019-12-28","s_pv":"0","sp_pv":"0","tags":null,"fenxiang_img":"http://cdn.iciba.com/web/news/longweibo/imag/2019-12-28.jpg","picture3":"","picture4":""}}*/
        if (jsonObj != null) {
            model = new DaliySentenceModel();
            String picUrl = jsonObj.getString("picture");

            String content = jsonObj.getString("note") + "<br/>" + jsonObj.getString("content");

            htmlContent = "<img src=\"" + picUrl + "\" width='270' >" + "<br/>";

            htmlContent += content;
            htmlContent += DaliySentenceUtil.getLinkedStr(getLinkURL(), getName());

            model.setHtmlContent(htmlContent);
            model.setContent(content);
            model.setOrigin(jsonObj.getString("from"));
            model.setPicUrl(picUrl); // 图片
            model.setBaseInfo(getBaseInfo());
        }
        return model;
    }

    @Override
    public String getKey() {
        return KEY;
    }

    @Override
    public String getName() {
        return NAME;
    }

    @Override
    public String getURL() {
        return URL_ICIBA;
    }

    @Override
    public String getLinkURL() {
        return LINK_URL;
    }

    @Override
    public String getDescription() {
        return DESCRIPTION;
    }

}
